package com.github.editor.zip;

import java.io.ByteArrayOutputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Map;
import java.util.zip.CRC32;

public abstract class IZipUtil {
    public abstract void exportFiles(String zip, String output, String... names) throws IOException;

    public abstract void createNew(String srcPath, String dstPath, Map<String, String> updateList) throws IOException;

    public static long getCrc32(String path) throws IOException {
        CRC32 crc32 = new CRC32();
        byte[] data = new byte[1024 * 4];
        int len;
        try (FileInputStream inputStream = new FileInputStream(path)) {
            while ((len = inputStream.read(data)) != -1) {
                crc32.update(data, 0, len);
            }
        }
        return crc32.getValue();
    }

    public byte[] ReadZipEntryBytes(String zip, String name) throws IOException{
        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
        ReadZipEntry(zip, name, outputStream);
        return outputStream.toByteArray();
    }

    public abstract void ReadZipEntry(String zip, String name, OutputStream outputStream) throws IOException;
}
